package com.fjwt.gz.core.constants;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wg
 * @Date 2019/11/16 15:09
 * @Description Constants 常量对象
 **/
public class CS {

    /** 可能需要根据环境 进行修改的地方 **/

    /** DB : 规则[必须32位， 支持数字和大小写字母]  */
    public static final String DB_KEY = "jeepayDJeIVzvyD6apRY7CSgmA3LN1Kk";

    //登录图形验证码缓存时间，单位：s
    public static final int VERCODE_CACHE_TIME = 60;


    /** 系统 角色 定义 **/
    public interface SYS_ROLE_TYPE{
        String MANAGER = "MANAGER"; // 平台： 一般指运营平台系统。 或者 或者平台收益者。
        String PROXY="PROXY"; //机构系统
        String MCH ="MCH"; //用户

        Map<String, String> SYS_ROLE_TYPE_MAP = new HashMap<>();
    }
    static {

        SYS_ROLE_TYPE.SYS_ROLE_TYPE_MAP.put(SYS_ROLE_TYPE.MANAGER, "运营平台");
        SYS_ROLE_TYPE.SYS_ROLE_TYPE_MAP.put(SYS_ROLE_TYPE.MCH, "商户系统");
        SYS_ROLE_TYPE.SYS_ROLE_TYPE_MAP.put(SYS_ROLE_TYPE.PROXY, "机构系统");
    }

    /** yes or no **/
    public static final byte NO = 0;
    public static final byte YES = 1;

    /** 通用 可用 / 禁用 **/
    public static final int PUB_USABLE = 1;
    public static final int PUB_DISABLE = 0;

    public static final Map<Integer, String> PUB_USABLE_MAP = new HashMap<>();
    static {
        PUB_USABLE_MAP.put(PUB_USABLE, "正常");
        PUB_USABLE_MAP.put(PUB_DISABLE, "停用");
    }

    /**短信验证码缓存key**/
    public static final String CACHE_KEY_SMS_CODE = "sms_code:%s:%s";
    public static final String CACHE_KEY_SMS_DAY_CNT = "sms_day_cnt:%s:%s";
    public static String getCacheKeySmsCode(String sysType, String phone){
        return String.format(CACHE_KEY_SMS_CODE, sysType, phone);
    }
    public static String getCacheKeySmsDayCnt(String sysType, String phone){
        return String.format(CACHE_KEY_SMS_DAY_CNT, sysType, phone);
    }

    /**
     * 性别 1- 男， 2-女
     */
    public static final byte SEX_UNKNOWN = 0;
    public static final byte SEX_MALE = 1;
    public static final byte SEX_FEMALE = 2;


    public static final long TOKEN_TIME = 60 * 60 * 2; //单位：s,  两小时

    public static final long TOKEN_TIME_APP = 60 * 60 * 24 * 30; //单位：s,  30天


    //access_token 名称
    public static final String ACCESS_TOKEN_NAME = "iToken";

    //version_key 名称
    public static final String ACCESS_VERSION_NAME = "HttpSecret:%s:%s:%s";
    public static String getVersionKeyToken(String sysType, Long userId, String key){
        return String.format(ACCESS_VERSION_NAME, sysType, userId, key);
    }

    //小程序隐私服务缓存
    public static final String PRIVACY_SERVICE_POLICY = "PrivacyService:%s";
    public static String getPrivacyService(String appId){
        return String.format(PRIVACY_SERVICE_POLICY, appId);
    }

    /** ！！不同系统请放置不同的redis库 ！！ **/
    /** 缓存key: 当前用户所有用户的token集合  example: TOKEN_1001_HcNheNDqHzhTIrT0lUXikm7xU5XY4Q */
    public static final String CACHE_KEY_TOKEN = "TOKEN:%s:%s_%s";
    public static String getCacheKeyToken(String sysType, Long sysUserId, String uuid){
        return String.format(CACHE_KEY_TOKEN, sysType, sysUserId, uuid);
    }

    /** 缓存key: 当前用户所有用户的token集合  example: tokenList_1001 */
    public static final String CACHE_KEY_TOKEN_LIST = "tokenList:%s:%s";
    public static String getCacheKeyTokenList(String sysType, Long uid){
        return String.format(CACHE_KEY_TOKEN_LIST, sysType, uid);
    }

    /** 图片验证码 缓存key **/
    public static final String CACHE_KEY_IMG_CODE = "img_code:%s";
    public static String getCacheKeyImgCode(String imgToken){
        return String.format(CACHE_KEY_IMG_CODE, imgToken);
    }


    /** 短信验证码 限制发送次数缓存key **/
    public static final String CACHE_KEY_SMS_CODE_Limit = "sms_code_limit:%s:%s";
    public static String getCacheKeySmsCodeLimit(String sysType, Long userId){
        return String.format(CACHE_KEY_SMS_CODE_Limit, sysType, userId);
    }

    /** 商户认证的时候短信验证码 缓存key **/
    public static final String CACHE_MCH_AUTH_SMS_CODE = "mch_auth_code:%s:%s";
    public static String getCacheMchAuthSmsCode(String sysType, String phone){
        return String.format(CACHE_MCH_AUTH_SMS_CODE, sysType, phone);
    }

    /** 添加用户时短信验证码 缓存key **/
    public static final String ADD_USER_CACHE_KEY_SMS_CODE = "add_user_sms_code:%s:%s";
    public static String addUserCacheKeySmsCode(String sysType, String phone){
        return String.format(ADD_USER_CACHE_KEY_SMS_CODE, sysType, phone);
    }
    /** 虚拟券充值短信验证码 缓存key **/
    public static final String VIRTUAL_AWARD_TOP_UP_SMS_CODE = "virtualAwardTopUp_sms_code:%s:%s";
    public static String getVirtualAwardTopUpSmsCode(String sysType, String phone){
        return String.format(VIRTUAL_AWARD_TOP_UP_SMS_CODE, sysType, phone);
    }

    /** 登录时短信验证码 缓存key **/
    public static final String LOGIN_CACHE_KEY_SMS_CODE = "login_sms_code:%s:%s";
    public static String getLoginCacheKeySmsCode(String sysType, String phone){
        return String.format(LOGIN_CACHE_KEY_SMS_CODE, sysType, phone);
    }

    /** 修改密码时短信验证码 缓存key **/
    public static final String UPDATEPWD_CACHE_KEY_SMS_CODE = "updatepwd_sms_code:%s:%s";
    public static String getUpdatepwdCacheKeySmsCode(String sysType, String phone){
        return String.format(UPDATEPWD_CACHE_KEY_SMS_CODE, sysType, phone);
    }

    /** 迁移积分短信验证码 缓存key **/
    public static final String MOVESCORE_CACHE_KEY_SMS_CODE = "movescore_sms_code:%s:%s";
    public static String getMoveScoreCacheKeySmsCode(String sysType, String phone){
        return String.format(MOVESCORE_CACHE_KEY_SMS_CODE, sysType, phone);
    }

    /** 预约有礼时短信验证码 缓存key **/
    public static final String BOOK_GIFT_SEND_MSG = "bookfift_sms_code:%s:%s";
    public static String getBookGiftSendMsg(String sysType, String phone){
        return String.format(BOOK_GIFT_SEND_MSG, sysType, phone);
    }

    /** 登录防穷举 缓存key **/
    public static final String CACHE_KEY_LOGIN_ERR = "LOGIN_ERR:%s_%s";
    public static String getCacheKeyLoginErr(String sysType, String username){
        return String.format(CACHE_KEY_LOGIN_ERR, sysType, username);
    }

    /** 小程序积分签到防并发 缓存key **/
    public static final String CACHE_KEY_FANS_SCORE_SIGN = "FANS_SCORE_SIGN:%s:%s";
    public static String getCacheKeyFansScoreSign(String sysType, Long userId){
        return String.format(CACHE_KEY_FANS_SCORE_SIGN, sysType, userId);
    }

    /** 单个机构信息 缓存key **/
    public static final String CACHE_KEY_AGENT_INFO = "AGENT_INFO:AGENT:%s";
    public static String getCacheKeyAgentInfo(String agentNo){
        return String.format(CACHE_KEY_AGENT_INFO, agentNo);
    }
    /** 多个机构信息 缓存key **/
    public static final String CACHE_KEY_AGENT_INFOS = "AGENT_INFO:AGENTS:%s";
    public static String getCacheKeyAgentInfos(String agentNo){
        return String.format(CACHE_KEY_AGENT_INFOS, agentNo);
    }

    /** 机构小程序配置信息 缓存key **/
    public static final String CACHE_KEY_APPLICATION_AGENT = "APPLICATION:%s:%s:%s";
    public static String getCacheKeyApplicationAgent(String agentNo, Integer type, String appid){
        return String.format(CACHE_KEY_APPLICATION_AGENT, agentNo, type, appid);
    }

    /** 小程序配置信息 缓存key **/
    public static final String CACHE_KEY_APPLICATION = "APPLICATION:%s";
    public static String getCacheKeyApplication(String appid){
        return String.format(CACHE_KEY_APPLICATION, appid);
    }

    /** 通道配置信息 缓存key **/
    public static final String CACHE_KEY_PAY_IFCODE = "PAY:%s";
    public static String getPayIfCode(String ifCode){
        return String.format(CACHE_KEY_PAY_IFCODE, ifCode);
    }

    /** 商户认证自主发券 缓存key **/
    public static final String COUPON_MCH_USER_CODE = "couponMch_user_code:%s:%s";
    public static String getCouponMchUserCode(String sysType, String phone){
        return String.format(COUPON_MCH_USER_CODE, sysType, phone);
    }

    /** 小程序用户注销 缓存key **/
    public static final String CACHE_KEY_FANS_USER_LOGOUT = "FANS_USER_LOGOUT:%s:%s";
    public static String getCacheKeyFansUserLogout(String sysType, String phone){
        return String.format(CACHE_KEY_FANS_USER_LOGOUT, sysType, phone);
    }

    /** 用户实名认证 缓存key **/
    public static final String CACHE_KEY_FANS_USER_REAL_NAME = "FANS_USER_REAL_NAME:%s:%s";
    public static String getCacheKeyFansUserRealName(String sysType, String phone){
        return String.format(CACHE_KEY_FANS_USER_REAL_NAME, sysType, phone);
    }

    /** 单个机构员工 缓存key **/
    public static final String CACHE_KEY_AGENT_EMPLOYEE = "AGENT_EMPLOYEE:%s:%s";
    public static String getCacheKeyAgentEmployee(String agentNo, String employeeNo){
        return String.format(CACHE_KEY_AGENT_EMPLOYEE, agentNo, employeeNo);
    }

    /** 请求防抖 缓存key **/
    public static final String CACHE_KEY_REQ_DEBOUNCE = "DEBOUNCE:%s:%s:%s:%s";
    public static String getCacheKeyReqDebounce(String sysType, String url, Long id, Integer paramHashCode){
        return String.format(CACHE_KEY_REQ_DEBOUNCE, sysType, url, id, paramHashCode);
    }

    /** 登录认证类型 **/
    public interface AUTH_TYPE{

        byte LOGIN_USER_NAME = 1; //登录用户名
        byte TELPHONE = 2; //手机号
        byte EMAIL = 3; //邮箱

        byte WX_UNION_ID = 10; //微信unionId
        byte WX_MINI = 11; //微信小程序
        byte WX_MP = 12; //微信公众号

    }

    //菜单类型
    public interface ENT_TYPE{

        String MENU_LEFT = "ML";  //左侧显示菜单
        String MENU_OTHER = "MO";  //其他菜单
        String PAGE_OR_BTN = "PB";  //页面 or 按钮

    }

    /** 代码（项目）层面 ， 全部的系统定义， 需要注入到对应的bean中 **/
    public interface CODE_SYS_NAME_SET {
        String GZ_MANAGER = "MANAGER";
        String GZ_MERCHANT = "MERCHANT";
        String GZ_PROXY = "PROXY";
    }

}
